<extend name="Layout:layout_list" />
<block name="head_after_block">
    <style type="text/css">form td { padding:3px;}</style>
</block>
<block name="body_content_block">
    <table id="main_grid" class="easyui-datagrid" data-url="{:AddonU('Recharge/get_recharge_list_json')}"></table>
    <div id="tb" style="padding:2px 5px;">
        <div style="margin-bottom: 5px; border-bottom:solid 1px #dddddd;">
            <a href="#" class="easyui-linkbutton lnk_grid_search" iconCls="icon-search" plain="true">搜索</a>
            <if condition="!$isSuperAdmin">
                <a href="#" class="easyui-linkbutton lnk-recharge">在线充值</a>
            </if>
        </div>
    </div>
    <!--隐藏区域-->
    <div style="display:none">
        <!--表格查询对话框-->
        <div id="dlg_search" style="padding:10px">            
            <form method="get" action="{:AddonU('Recharge/get_recharge_list_json')}" data-export-url="{:AddonU('Recharge/recharge_export')}">
                <input type="text" name="begindate" class="easyui-datebox" value="{$search.begindate}"/> 至
                <input type="text" name="enddate" class="easyui-datebox" value="{$search.enddate}"/>
                <if condition="$isSuperAdmin">
                    用户名：<input type="text" name="siteID" id="siteID" class="easyui-combobox" data-url="{:AddonU('Admin/get_admin_json')}" />
                    <else/>
                    <input type="hidden" name="siteID" value="{$loginData.siteID}"/>
                </if>
                充值来源：<select name="origin">
                    <option value="">所有</option>
                    <option value="现金">现金</option>
                    <option value="转账">转账</option>
                    <option value="在线支付">在线支付</option>
                </select>
            </form>
        </div>
        <!--/表格查询对话框-->
        <!--充值对话框-->
        <div id="dlg_recharge" title="在线充值" style="padding:10px;">
            <form name="alipayment" action="/xcall/trade_create_by_buyer/alipayapi.php" method="post" target="_blank">
                <table>
                    <tr><th>充值金额：</th><td><input type="text" name="WIDprice" style="width:60px;" value="500" required class="easyui-textbox"/>（最少500元）</td></tr>
                    <tr><th>备注：</th><td><input type="text" name="WIDremark" class="easyui-textbox"/></td></tr>
                </table>
                <input type="hidden" name="WIDseller_email" value="xiamenxyx@163.com" title="卖家支付宝帐户"/>
                <input type="hidden" name="WIDout_trade_no" value="" title="商户订单号" data-prefix="FR-{$loginData.siteID}-"/>
                <input type="hidden" name="WIDsubject" value="XCALL系统话费充值" title="订单名称"/>
                <input type="hidden" name="WIDbody" value="" title="订单描述"/>
                <input type="hidden" name="WIDshow_url" value="" title="商品展示地址"/>
                <input type="hidden" name="WIDreceive_name" value="厦门鑫优祥" title="收货人姓名"/>
                <input type="hidden" name="WIDreceive_address" value="福建厦门莲岳路189号" title="收货人地址"/>
                <input type="hidden" name="WIDreceive_zip" value="361012" title="收货人邮编"/>
                <input type="hidden" name="WIDreceive_phone" value="05925861999" title="收货人电话号码"/>
                <input type="hidden" name="WIDreceive_mobile" value="13606908888" title="收货人手机号码"/>
                <input type="hidden" name="siteID" value="{$loginData.siteID}"/>
            </form>
        </div>
        <!--/充值对话框-->
    </div>
    <!--/隐藏区域-->
</block>
<block name="body_after_block">
    <script type="text/javascript">
        // 页面初始化
        Date.prototype.format = function (format) {
            var o = {
                "M+": this.getMonth() + 1, //month 
                "d+": this.getDate(), //day 
                "h+": this.getHours(), //hour 
                "m+": this.getMinutes(), //minute 
                "s+": this.getSeconds(), //second 
                "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 
                "S": this.getMilliseconds() //millisecond 
            }

            if (/(y+)/.test(format)) {
                format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }

            for (var k in o) {
                if (new RegExp("(" + k + ")").test(format)) {
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
                }
            }
            return format;
        }
        $('.lnk-recharge').click(function () {
            $('input[name="WIDout_trade_no"]').val($('input[name="WIDout_trade_no"]').data('prefix') + new Date().format('yyyyMMddhhmmss'));
            $('#dlg_recharge').dialog({
                width: 270,
                height: 150,
                resizable: true,
                buttons: [{
                        text: "取消",
                        handler: function () {
                            $('#dlg_recharge').dialog("close");
                        }
                    }, {
                        text: "确定",
                        handler: function () {
                            var val = $('input[name="WIDprice"]').val();
                            if (!val) {
                                alert('充值金额无效!')
                                return;
                            }
                            var vmx = true;
                            if (val[0] == '?') {
                                vmx = false;
                                val = val.substring(1);
                            }
                            if (isNaN(val)) {
                                alert('充值金额无效!')
                                return;
                            }
                            if (vmx && val < 500) {
                                alert('充值最少500元!')
                                return;
                            }
                            $('form[name="alipayment"]').submit();
                            $('#dlg_recharge').dialog("close");
                        }
                    }]
            });
            return false;
        })
        var curd_grid = CurdGrid.newInstance();
        curd_grid.before_search_dialog = function () {
            $('#siteID').combobox({url: $('#siteID').data('url'), valueField: 'id', textField: 'text'});
        }
        curd_grid.config({
            title: '充值管理',
            toolbar: '#tb',
            fitColumns: true,
            showFooter: true,
            columns: [[
                    {title: "租户ID", field: "siteID", sortable: true, formatter: function (value, row) {
                            if (value) {
                                return row.userName + '[' + value + ']';
                            }
                        }},
                    {title: "充值金额", field: "amount"},
                    {title: "备注", field: "remark", sortable: true},
                    {title: "充值来源", field: "origin", sortable: true},
                    {title: "充值时间", field: "createdTime", sortable: true},
                ]],
        });
        curd_grid.init();
    </script>
</block>